// miniprogram/pages/bar/index/user/lease/lease.js
const APIUrl = require('../../../../../tools/APIurl');
const mAPIUrl = new APIUrl()
var that
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bill: [{
      title: "房租",
      titleId: "0",
      show:true,
      content:500
    }, {
      title: "水费",
      titleId: "1",
      show:true,
      content:100
    },{
      title: "电费",
      titleId: "2",
      show:true,
      content:100
    },{
      title: "网费",
      titleId: "3",
      show:true,
      content:50
    }
  ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that =this;
    that = this
    var year=new Date().getFullYear()
    var month=new Date().getMonth()+1
    var day = new Date().getDate()
    mAPIUrl.list('/api/mgr/bill',{
      action: 'listGuest',
      guests_id: wx.getStorageSync('userInfo').id,
      end_time:year+'-'+(month < 10 ? '0' + month : month)
    },function(res){
      console.log(res)
      var remind = that.data.remind
      var receivedTotal = 0
      var bill = that.data.bill
      bill[0].content=parseFloat(res[0].all_cost)-parseFloat(res[0].electricity_cost)-parseFloat(res[0].network_cost)-parseFloat(res[0].water_cost)
      bill[1].content=res[0].water_cost
      bill[2].content=res[0].electricity_cost
      bill[3].content=res[0].network_cost
      that.setData({
        bill:bill,
        totalAmount:res[0].all_cost
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})